package com.yeci.service.impl;

import com.github.pagehelper.PageHelper;
import com.yeci.common.page.PageDomain;
import com.yeci.common.page.TableSupport;
import com.yeci.common.utils.SqlUtil;
import com.yeci.common.utils.StringUtil;
import com.yeci.entity.SysBlog;
import com.yeci.mapper.SysBlogMapper;
import com.yeci.service.SysBlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yeci
 * @since 2021-08-12
 */
@Service
public class SysBlogServiceImpl extends ServiceImpl<SysBlogMapper, SysBlog> implements SysBlogService {

  @Autowired
  private SysBlogMapper blogMapper;

  @Override
  public List<SysBlog> selectSysBlogList(SysBlog sysBlog){
    startPage();
    List<SysBlog> sysBlogs = blogMapper.selectBlogList(sysBlog);
    return sysBlogs;
  }

  /**
   * 设置请求分页数据
   */
  protected void startPage()
  {
    PageDomain pageDomain = TableSupport.buildPageRequest();
    Integer pageNum = pageDomain.getPageNum();
    Integer pageSize = pageDomain.getPageSize();
    System.out.println(pageNum);
    System.out.println(pageSize);
    if (StringUtil.isNotNull(pageNum) && StringUtil.isNotNull(pageSize))
    {
      String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
      PageHelper.startPage(pageNum, pageSize, orderBy);
    }
  }

}
